package com.example.demo.internettongxin.bsjiagouplus;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @Description Server
 * @Author songchuanlong
 * @Date 2025-05-30
 */
public class Server {
    public static void main(String[] args) throws Exception {
        ServerSocket serverSocket = new ServerSocket(9998);
        //创建线程池，负责处理通信管道的任务
        ThreadPoolExecutor tpe = new ThreadPoolExecutor(8 * 2, 8 * 2, 0,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(8),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy());
        while (true) {
            Socket socket = serverSocket.accept();
            System.out.println(socket.getRemoteSocketAddress()+"有人上线了");
            tpe.execute(new ServerThread(socket));
        }
    }
}
